store cached fishes in ~/.cache/babl
authorØyvind Kolås <pippin@gimp.org>
Tue, 15 Nov 2016 16:02:10 +0000 (17:02 +0100)
committerØyvind Kolås <pippin@gimp.org>
Tue, 15 Nov 2016 16:02:12 +0000 (17:02 +0100)
Still no fish cache path solution for win32

babl/babl-cache.c

index 42a704d47640c762769bfe29049688e449661d02..35ae2602d1710ff92fc555f900fad2c3cb39403a 100644 (file)
  */
 
 #include <time.h>
+#include <sys/stat.h>
 #include "config.h"
 #include "babl-internal.h"
 #include "git-version.h"
 
 static const char *fish_cache_path (void)
 {
-  return "/tmp/babl.db"; // XXX: a $HOME/.cache/babl/fishes path might be better
+  // FIXME: need a location for this temporary file on win32
+  struct stat stat_buf;
+  static char resolved[4096];
+  char *ret = NULL;
+  if (getenv ("HOME"))
+  {
+    sprintf (resolved, "%s/.cache/babl/fishes", getenv("HOME"));
+  }
+  else
+  {
+    return "/tmp/babl.db";
+  }
+
+  if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
+    return resolved;
+  ret = strdup (resolved);
+
+  while (strrchr (resolved, '/'))
+  {
+    *strrchr (resolved, '/') = '\0';
+    mkdir (resolved, S_IRWXU);
+  }
+
+  strcpy (resolved, ret);
+  free (ret);
+
+  return resolved;
 }
 
 static char *